// pages/1/index.js
import wxCharts from '../../utils/wxcharts.js'
const app = getApp()
const name = [];
const num = [];
const lists = [];
const pieName = [];
const nums = [];
const arr = [];
const arr1 = [];
var json = [];
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: ['../images/banner.png', '../images/banner.png'],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    color: 'rgba(255,255,255,.5)',
    active: '#fff',
    currentTab: 0,
  },
  /** 
    * 滑动切换tab 
    */
  bindChange: function (e) {
    var that = this;
    that.setData({ currentTab: e.detail.current });
  },

  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {

      return false;

    } else {

      that.setData({

        currentTab: e.target.dataset.current

      })

    }

  },
  getNolead: function (res) {
    name.splice(0, name.length)
    num.splice(0, num.length)
    for (var i = 0; i < res.length; i++) {
      name.push(res[i].name);
      num.push(res[i].num);
    }
    new wxCharts({
      canvasId: 'columnCanvas',
      type: 'column',
      animation: true,
      categories: name,
      series: [{
        data: num,
        color: '#FF2A0B'
      }],
      yAxis: {
        min: 0
      },
      xAxis: {
        disableGrid: false,
        type: 'calibration'
      },
      extra: {
        column: {
          width: 20
        }
      },
      width: 300,
      height: 200,
      dataLabel: true,
      legend: false
    });
  },
  getyearMoney: function (res) {
    arr.splice(0, arr.length)
    arr1.splice(0, arr1.length)
    json.splice(0, json.length)
    var color = ["#a6fe54", "#1E385D", "#DFFE1A", "#24DBFA", "#50ACEF", "#02B3D5", "#000ADE", "#C9FCC1", "#4FA8FA", "#FC6763"]
    var list = res[0]
    for (let i in list) {
      arr.push(list[i])
    }
    for (let key in list) {
      arr1.push(key)
    }
    for (var i = 0; i < arr.length; i++) {
      var j = {}
      j.name = arr1[i]
      j.data = arr[i]
      j.color = color[i]
      // 这里还可以继续添加属性 j.属性 = 值
      json.push(j)
    }
    console.log(json)
    new wxCharts({
      animation: true,
      canvasId: 'pieCanvas',
      type: 'pie',
      series: json,
      width: 300,
      height: 300,
      dataLabel: true
      // legend:true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.thirdScript.http.post('project/getyearMoney', { street: wx.getStorageSync('userInfo').officeName }, 'getyearMoney', this)
    app.thirdScript.http.post('project/getNolead', { street: wx.getStorageSync('userInfo').officeName }, 'getNolead', this)

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */

  onReady: function () {


  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})